x`
<template>
  <h1>住院信息</h1>
  <el-row :gutter="10">

        <el-col :span="6">
          <el-input v-model="query.InHospitalData.patientName" placeholder="请输入病人姓名" style="width: 200px;" />
        </el-col>



    <el-col :span="6">
      <el-select v-model="query.InHospitalData.roomId"
                 :clearable="true"
                 placeholder="房间号">
        <el-option v-for="item in roomIds.data"
                   :key="item.roomId"
                   :label="item.roomNumber"
                   :value="item.roomId" />
      </el-select>
    </el-col>

<!--        <el-col :span="6">-->
<!--          <el-select v-model="query.InHospitalData.departmentId"-->
<!--                     :clearable="true"-->
<!--                     placeholder="请选择科室">-->
<!--            <el-option v-for="item in departments.data"-->
<!--                       :key="item.departmentId"-->
<!--                       :label="item.departmentName"-->
<!--                       :value="item.departmentId" />-->
<!--          </el-select>-->
<!--        </el-col>-->

<!--        <el-col :span="6">-->
<!--          <el-select v-model="query.InHospitalData.gender"-->
<!--                     :clearable="true"-->
<!--                     placeholder="请选择性别">-->
<!--            <el-option label="男" value="1" />-->
<!--            <el-option label="女" value="0" />-->
<!--          </el-select>-->
<!--        </el-col>-->

        <el-col :span="6">
          <el-button type="primary" @click="getInHospitalData(query.InHospitalData)">搜索</el-button>
        </el-col>

  </el-row>
  <el-table :data="tableData.data" style="width: 100%;margin-top: 20px">

    <el-table-column label="序号" type="index" width="80" align="center">
    </el-table-column>

    <el-table-column label="姓名" prop="patientName" width="100" align="center">
    </el-table-column>

    <el-table-column label="性别" prop="gender" width="100" align="center">
    </el-table-column>

    <el-table-column label="病房号" prop="roomNumber" width="100" align="center">
    </el-table-column>

    <el-table-column label="病床号" prop="bedNum" width="100" align="center">
    </el-table-column>

    <el-table-column label="病房地址" prop="address" width="100" align="center">
    </el-table-column>


    <el-table-column label="科室" prop="departmentName" width="100" align="center">
    </el-table-column>


    <el-table-column label="身份证" prop="identity" width="200" align="center">
    </el-table-column>


    <el-table-column label="创建日期" width="130px" align="center">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon>
            <timer />
          </el-icon>
          <span style="margin-left: 10px">{{scope.row.outTime !==null? scope.row.outTime.slice(0, 10): "未出院" }}</span>
        </div>
      </template>
    </el-table-column>

    <el-table-column label="操作" width="250px" align="center">
      <template #default="scope">
        <el-button
          style="width: 60px;"
          size="small"
          @click="handleEdit(scope.row)"
        >修改
        </el-button>
        <el-button
          style="width: 60px;"
          size="small"
          type="danger"
          v-model:current-page="query.InHospitalData.pages"
          v-model:age-sizes="query.InHospitalData.size"
          @click="handleDelete(scope.row)"
        >删除
        </el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!--分页组件-->
  <div style=" display: flex;
  justify-content: flex-end;">
    <el-pagination
      small
      layout="total, prev, pager, next, jumper"
      :total="tableData.total"
      class="pagiantion "
      @current-change="pageChange"
      v-model:current-page="query.InHospitalData.pages"
      v-model:page-size="query.InHospitalData.size"
    />
  </div>
</template>

<script lang="js" setup>
import { Timer } from "@element-plus/icons-vue";
import { onMounted, reactive, ref } from "vue";
import { deleteInHospitalApi, getInHospitalApi } from "@/utils/InHospitalRequest";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
import { getRoomIdAndNumberApi } from "@/utils/RoomRequest";

const router = useRouter();

//弹窗
const outerVisible = ref(false);

//弹出数据
const outerVisibleData = reactive(
  {
    msg: "",
    data: []
  }
);

//展示数据
const tableData = reactive({
  data: [],
  total: 0,
  current: 1, //当前页数
  size: 2  //每页显示几条数据
});
const departments = reactive({
  data: []
});
//请求参数
const query = reactive({
  InHospitalData: {
    "bedId": "",
    "createTime": "",
    "doctorId": "",
    "patientName":"",
    "inHospitalId": "",
    "isDelete": "",
    "outTime": "",
    "patientId": "",
    "roomId": "",
    "updateTime": "",
    "pages": tableData.current,
    "size": tableData.size
  }
});

//病房的id和房间号
const roomIds = reactive({
  data: []
});


//组件加载时触发
onMounted(() => {
  getInHospitalData(query.InHospitalData);
  getRooIdAndRoomNumber(3);
});

//获取病房间的id和房间号
const getRooIdAndRoomNumber = async (id) => {
  //发送请求
  let res = await getRoomIdAndNumberApi(id);
  // 为roomIds.data 赋值
  roomIds.data = res.data;
};


//获取数据
const getInHospitalData = async (requestData) => {
  let res = await getInHospitalApi(requestData);
  tableData.data = res.data;
  tableData.total = res.total;
  tableData.current = res.current;
};

//分页的页码变化时触发
const pageChange = () => {
  // console.log(query.employeeData.pages);
  getInHospitalData(query.InHospitalData);
};

//修改回调
const handleEdit = (row) => {
  router.push({
    path: "/home/updatemps",
    query: { id: row.employeeId }
  });
};

//弹窗回调
const handleMsg = (row) => {
  outerVisible.value = true;
  outerVisibleData.msg = row.description.msg;
  outerVisibleData.data = row.description.list;
};

//删除
const handleDelete = (row) => {
  ElMessageBox.confirm(
    "确定要删除吗?",
    "警告",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
  )
    .then(async () => {
      let res = await deleteInHospitalApi(row.inHospitalId);
      if (res.data) {
        ElMessage({
          type: "success",
          message: "删除成功"
        });
      } else {
        ElMessage({
          type: "error",
          message: "删除成功"
        });
      }
      getInHospitalData(query.InHospitalData);
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除"
      });
    });
};

</script>

<style scoped>
:global(.el-dialog__body) {
  padding: 10px;
}
.msg{
  margin-left: 20px;
  font-size: 15px;
}
</style>